#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> ret;
    while (n--)
    {
        int k;
        cin >> k;
        while (k--)
        {
            int num;
            cin >> num;
            ret.push_back(num);
        }
    }

    unordered_map<int, int> hash;
    for (int num : ret)
    {
        hash[num]++;
    }

    int max = 0;
    int maxnum = 0;
    for (const auto& pair : hash)
    {
        if (pair.second > max)
        {
            max = pair.second;
            maxnum = pair.first;
        }
        if (pair.second == max)
        {
            max = pair.second;
            maxnum = pair.first > maxnum ? pair.first : maxnum;
        }
    }

    cout << maxnum << " " << max << endl;
    return 0;
}